<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	layout:decorator="layout/default">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>身份委托</title>
</head>
<body>
	<div layout:fragment="content">
		<div class="page-header">
			<h1>身份委托</h1>
		</div>
		<div class="row">
			<div class="col-lg-12 col-md-12 col-sm-12 xol-xs-12">
				<p>
					当您因客观原因不能登录网站进行一些操作时，想把工作委托给您的同事，但又不想告诉他（她）您的帐号密码时，就可以使用到<strong>身份委托</strong>功能。
					您只需指定委托人，及委托日期（可以是一个临时性委托，也可以是永久性委托），他（她）就可以以您的身份在系统中进行操作。
				</p>
			</div>
		</div>
		<div class="row">
			<div class="col-lg-6 col-md-6 col-sm-12 xol-xs-12">
				<div th:replace="auth/delegate/index::showDelegates(${delegates}, ${previousUser})"></div>
			</div>
			<div class="col-lg-6 col-md-6 col-sm-12 xol-xs-12">
				<div th:replace="auth/delegate/index::showClients(${clients})"></div>
			</div>
		</div>

		<div class="row" th:if="${candidates}">
			<div class="col-lg-12 col-md-12 col-sm-12 xol-xs-12">
				<div class="panel panel-success">
					<div class="panel-heading">委托候选人</div>
					<div class="table-responsive">
						<table class="table table-striped table-hover table-condensed">
							<thead>
								<tr>
									<th>登录名称</th>
									<th>显示昵称</th>
									<th>电子邮件</th>
									<th>状态</th>
									<th>创建时间</th>
									<th>更新时间</th>
									<th></th>
								</tr>
							</thead>
							<tbody>
								<tr data-th-each="user, state: ${candidates}"
									data-th-object="${user}">
									<td><a data-th-href="@{'/users/' + *{userId}}"
										data-th-text="*{userName}"></a></td>
									<td data-th-text="*{nickName}"></td>
									<td><a data-th-text="*{email}"
										th:href="@{'mailto:' + *{email}}"></a></td>
									<td data-th-text="*{state}"></td>
									<td><span th:if="*{createdTime}"
										th:text="*{#dates.format(createdTime, 'yyyy-MM-dd HH:mm:ss')}"></span></td>
									<td><span th:if="*{updateTime}"
										th:text="*{#dates.format(updateTime, 'yyyy-MM-dd HH:mm:ss')}"></span></td>
									<td><a class="btn btn-primary btn-xs" title="将此用户设为我的代理人"
										th:href="@{/delegate/grant/{id}(id=*{userId})}">委托给TA</a></td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div class="panel panel-success" th:fragment="showClients(clientList)">
		<div class="panel-heading">我的受托</div>
		<div class="panel-body" th:if="${#lists.isEmpty(clientList)}">
			<small class="text-muted">无受托记录！</small>
		</div>
		<div class="table-responsive"
			th:unless="${#lists.isEmpty(clientList)}">
			<table class="table table-striped table-hover table-condensed">
				<thead>
					<tr>
						<th>委托人</th>
						<th>生效日期</th>
						<th>终止日期</th>
						<th></th>
					</tr>
				</thead>
				<tbody>
					<tr th:each="client: ${clientList}" th:object="${client}">
						<td th:utext="*{fromUser.nickName}"></td>
						<td><span th:if="*{startDate}"
							th:text="*{#dates.format(startDate, 'yyyy-MM-dd')}"></span></td>
						<td><span th:if="*{endDate}"
							th:text="*{#dates.format(endDate, 'yyyy-MM-dd')}"></span></td>
						<td><a class="btn btn-success btn-xs" title="切换到委托人身份"
							th:href="@{/delegate/switchTo/{id}(id=*{fromUser.userId})}">切换身份</a></td>
					</tr>
				</tbody>
			</table>
		</div>
		<div class="panel-footer" th:if="${!#lists.isEmpty(clientList)}">
			<small> 您已获得以上用户的委托，可以使用右侧的 <code>切换身份</code>
				按钮切换到委托人身份在系统中执行操作！
			</small>
		</div>
	</div>

	<div class="panel panel-success" th:fragment="showDelegates(delegateList, previousUser)">
		<div class="panel-heading">
			我的委托
			<div class="btn-toolbar pull-right hidden-print"
				th:if="${previousUser}">
				<div class="btn-group btn-group-xs">
					<a class="btn btn-default" th:href="@{/delegate/switchBack}">返回<strong
						th:utext="${previousUser.nickName}" class="text-primary"
						style="padding-left: 4px; padding-right: 4px;"></strong>的身份
					</a>
				</div>
			</div>
		</div>
		<div class="panel-body" th:if="${#lists.isEmpty(delegateList)}">
			<small class="text-muted">无委托记录！</small>
		</div>
		<div class="table-responsive"
			th:unless="${#lists.isEmpty(delegateList)}">
			<table class="table table-striped table-hover table-condensed">
				<thead>
					<tr>
						<th>受托人</th>
						<th>生效日期</th>
						<th>终止日期</th>
						<th th:unless="${previousUser}"></th>
					</tr>
				</thead>
				<tbody>
					<tr th:each="delegate: ${delegateList}" th:object="${delegate}">
						<td th:utext="*{toUser.nickName}"></td>
						<td><span th:if="*{startDate}"
							th:text="*{#dates.format(startDate, 'yyyy-MM-dd')}"></span></td>
						<td><span th:if="*{endDate}"
							th:text="*{#dates.format(endDate, 'yyyy-MM-dd')}"></span></td>
						<td th:unless="${previousUser}"><a
							class="btn btn-warning btn-xs" title="取消代理人身份"
							th:href="@{/delegate/revoke/{id}(id=*{toUser.userId})}">取消委托</a></td>
					</tr>
				</tbody>
			</table>
		</div>
		<div class="panel-footer" th:if="${!#lists.isEmpty(delegateList)}">
			<small>您已将身份委托给以上用户，他们可以在<strong class="text-danger">有效的委托时间范围以您的身份在系统中执行操作</strong>。<span
				th:unless="${previousUser}">使用右侧的 <code>取消委托</code> 按钮取消身份委托！
			</span>
			</small>
		</div>
	</div>
</body>
</html>
